
do "E:/ReplicateBuild/02_code/00_environment/00_set_environment.do"

		tempfile tempstore
		
		forval y = 2006/2018 {

		    di "Starting Year `y'" 
			qui {
		    import sas using "$rawdata/Student/Suspension/mastsusp`y'.sas7bdat", clear
			
			if `y'<=2007 {
			    gen anyOSS = (inlist(c_conseq1,"003","004","005") | inlist(c_conseq2,"003","004","005") | inlist(c_conseq3,"003","004","005"))
				gen anyISS = (inlist(c_conseq1,"002") | inlist(c_conseq2,"002") | inlist(c_conseq3,"002"))
			} 
			if `y'>2007 & `y'<=2015 {
			    gen anyOSS = (inlist(consqtype1,"003","004","005") | inlist(consqtype2,"003","004","005") | inlist(consqtype3,"003","004","005"))
				gen anyISS = (inlist(consqtype1,"002") | inlist(consqtype2,"002") | inlist(consqtype3,"002"))
			} 
			if `y'>2015 & `y'<=2018 {
				gen anyOSS = OSS_DAYS>0 & OSS_DAYS!=.
				gen anyISS = ISS_DAYS>0 & ISS_DAYS!=.
			} 

			collapse (max) anyOSS anyISS, by(mastid)
			gen year = `y'
		}
		summ anyOSS anyISS
		if `y'>2006 {
			append using `tempstore'
		}
		save `tempstore', replace
		}
			
		save "$basedata/suspensions", replace
		
		tempfile tempstore
		
		forval y = 2006/2015 {
		    di "Starting Year `y'" 
			qui {
			if `y' != 2013 & `y' != 2014 {
		    import sas using "$rawdata/Student/MBuild/Absence and demographics/accdemopub`y'.sas7bdat", clear
			}
			if `y' == 2013 | `y' == 2014 {
		    import sas using "$rawdata/Student/MBuild/Absence and demographics/accdemo_pub`y'.sas7bdat", clear
			}
			
		cap destring daysabs, force replace
		cap destring daysmem, force replace
		gen attendance_rate = 1-daysabs/daysmem
		
		replace attendance_rate = . if attendance_rate>1 | attendance_rate<=0

			collapse (max) attendance_rate, by(mastid)
			gen year = `y'
		}
		summ attendance_rate
		if `y'>2006 {
			append using `tempstore'
		}
		save `tempstore', replace
		}
		forvalues y = 2016/2017{
			import sas using "$rawdata/Student/MBuild/Absence and demographics/mergedemo_pub`y'.sas7bdat", clear
			cap destring daysabs, force replace
		cap destring daysmem, force replace
		gen attendance_rate = 1-daysabs/daysmem
		
		replace attendance_rate = . if attendance_rate>1 | attendance_rate<=0

			collapse (max) attendance_rate, by(mastid)
			gen year = `y'
					summ attendance_rate
		if `y'>2006 {
			append using `tempstore'
		}
		save `tempstore', replace
		
		}
		
		
			forval y = 2018/2019 {
		    di "Starting Year `y'" 
			qui {
		    import sas using "$rawdata/Student/MBuild/Absence and demographics/attendance_pub`y'.sas7bdat", clear
				cap destring daya, force replace
		cap destring daye, force replace
		gen attendance_rate = 1-daya/daye
		
		
		replace attendance_rate = . if attendance_rate>1 | attendance_rate<=0

			collapse (max) attendance_rate, by(mastid)
			gen year = `y'
		}
		summ attendance_rate
		
		if `y'>2006 {
			append using `tempstore'
		}
		save `tempstore', replace
		
		}
			
		save "$basedata/attendance_mb", replace
		
		
		